<?php

namespace Admin\Model;

use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Select;


class CounterTable extends AbstractTableGateway {

    protected $table = 'counter';
	

    public function __construct(Adapter $adapter) {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new ResultSet();
        $this->resultSetPrototype->setArrayObjectPrototype(new Counter());

        $this->initialize();
    }

    
	
	 public function fetchDay(Select $select = null) {
        if (null === $select)
            $select = new Select();
        $select->from($this->table,array('*'));
        $resultSet = $this->selectWith($select);
        $row = $resultSet->current();
        return $row;
    }
	public function fetchMonth(Select $select = null) {
        if (null === $select)
            $select = new Select();
        $select->from($this->table)->columns(array(new \Zend\Db\Sql\Expression('SUM(`luongtruycap`) as `luongtruycap`,SUM(`soluotxem`) as `soluotxem`'),'thang','nam'))->group('thang')->order('id desc')->limit(12);
        $resultSet = $this->selectWith($select);
        $row = $resultSet->current();
        return $row;
    }
	
	


}
